<?php

/** 
 * @author Nguyen
 * 
 */
class ResourceMessage {
	private static $_type;
	private $_resourceArray;
	private static $_instance;
	/**
	 */
	private function __construct($type = null) {
		if ($type == null) {
			self::$_type = Configuration::RESOURCE_DEFAULT;
		} else {
			self::$_type = $type;
		}
		$this->_resourcePath = RESOURCE_PATH . SLASH . 'message.' . self::$_type . Configuration::RESOURCE_DEFAULT_EXT;
		if (! file_exists ( $this->_resourcePath )) {
			Log::error ( "Resource", "Resource " . $this->_resourcePath . ' not found!' );
			if (Configuration::DEBUG_MOD)
				throw new ResourceException ( "Resource " . $this->_resourcePath . ' not found!' );
			$this->_resourcePath = RESOURCE_PATH . SLASH . 'message.' . Configuration::RESOURCE_DEFAULT . Configuration::RESOURCE_DEFAULT_EXT;
		}
		$this->_resourceArray = parse_ini_file ( $this->_resourcePath );
	}
	/**
	 *
	 * Get ResourceMessage Instance.
	 * @param String $type
	 * @return ResourceMessage
	 */
	public static function getInstance($type = null){
		if(!self::$_instance|| $type != self::$_type){
			self::$_instance = new ResourceMessage($type);
		}
		return self::$_instance;
	}/**
	 * Get Resource String ...
	 * @param String $name
	 */
	public function getMessage($name){
		return (isset($this->_resourceArray[$name]))?$this->_resourceArray[$name]:STRING_EMPTY;
	}
	public function getMessage2($name,array $parram){
		$str = (isset($this->_resourceArray[$name]))?$this->_resourceArray[$name]:STRING_EMPTY;
		return StringUltil::format($str, $parram);
	}
}

?>